package com.tedu.weibo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;


@Component
@Aspect
@Slf4j
public class LogAspect {

    @Before("execution(public com.tedu.weibo.result.JsonResult com.tedu.weibo.controller.*.*(..))")
    public void before(JoinPoint joinPoint){
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        System.out.println("1212");
        log.info(className+"."+methodName+"()方法开始执行");
    }
    @AfterReturning("execution(public com.tedu.weibo.result.JsonResult com.tedu.weibo.controller.*.*(..))")
    public void afterReturning(JoinPoint joinPoint){
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        log.info(className+"."+methodName+"()方法执行完毕");
    }

    @AfterThrowing(value = "execution(public com.tedu.weibo.result.JsonResult com.tedu.weibo.controller.*.*(..))",throwing = "t")

    public void afterThrowing(JoinPoint joinPoint,Throwable t){

        log.error(t.getMessage(),t);
    }
}
